// ==UserScript==
// @name         【HUHA】Epoint流程快一点
// @namespace    http://tampermonkey.net/
// @version      2024-05-29
// @description  让新点的流程快一点
// @author       You
// @match        https://gitee.com/huhage/epoint_-editor_-tampermonkey-js
// @match        https://oa.epoint.com.cn/OA9/oa9/mail/mailreceivedetail*
// @match        https://oa.epoint.com.cn/OA9/oa9/mail/mailsend*
// @match        https://oa.epoint.com.cn/OA9/oa9/mail/mailsenddetail*
// @match        https://oa.epoint.com.cn/topic/frame/pages/communitynew/index*
// @match        https://fdoc.epoint.com.cn/onlinedoc/kfzknowledge/customoa/infofeedback*
// @match        https://fdoc.epoint.com.cn/onlinedoc/kfzknowledge/kfzknowledge/postquestion_workflow*
// @match        https://oa.epoint.com.cn/productrelease/cpzt/demandmanagezw/demandbasicinfonew_workflow*
// @match        https://oa.epoint.com.cn/productrelease/cpzt/demandmanagejy/demandfeedbackadd*
// @match        https://oa.epoint.com.cn/productrelease/cpzt/demandmanagejy/demandbasicinfonew_detail*
// @match        https://oa.epoint.com.cn/productrelease/cpzt/demandmanagejy/demandbasicinfonew_splitdetail*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=gitee.com
// @grant        none
// ==/UserScript==

(function () {
    window.UEDITOR_HOME_URL = 'https://oa.epoint.com.cn/oaextend/designengine/assets/plugins/ueditor-plus/3.8.0/';
    var BASE_URL = 'https://fe.epoint.com.cn/showcase/everyone/tampermonkey-epoint-editor-replace/';
    var version = '0.2.0';
    var urls = ['ueditor.config.js', 'ueditor.all.js', 'lang/zh-cn/zh-cn.js'].map((url) => UEDITOR_HOME_URL + url + '?v=' + version);

    // prettier-ignore
    var simpleToolbars = [
        ['fullscreen', 'source', '|', 'undo', 'redo', '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', '|', 'rowspacingtop', 'rowspacingbottom'],
        ['fontfamily', 'fontsize', 'lineheight', '|', 'simpleupload', 'insertcode', 'pagebreak', '|', 'horizontal', 'date', 'time', '|', 'inserttable', 'deletetable', 'preview']
    ];

    console.log('================================');
    console.log('tampermonkey-epoint-editor-replace: V' + version);

    function dirtyCheckhashChanged(callback) {
        var lastHash = '';
        if (typeof callback !== 'function') {
            callback = function () {};
        }
        setInterval(() => {
            if (location.hash != lastHash) {
                callback();
                lastHash = location.hash;
            }
        }, 200);
    }

    var LOAD = {
        _loadedJs: {},
        loadJs: (function () {
            function loadOne(url, callback) {
                if (LOAD._loadedJs[url]) {
                    if (typeof callback === 'function') {
                        if (LOAD._loadedJs[url].loaded) {
                            callback();
                        } else {
                            LOAD._loadedJs[url].callbacks.push(callback);
                        }
                    }
                    return;
                }

                var script = document.createElement('script');
                script.type = 'text/javascript';
                script.onload = function () {
                    executeCallback();
                    script.onload = null;
                };

                function executeCallback() {
                    LOAD._loadedJs[url].loaded = true;

                    var callbacks = LOAD._loadedJs[url].callbacks;
                    if (callbacks) {
                        for (var i = 0, l = callbacks.length; i < l; i++) {
                            callbacks[i]();
                        }
                        LOAD._loadedJs[url].callbacks = [];
                    }
                }

                LOAD._loadedJs[url] = {
                    loaded: false,
                    callbacks: []
                };
                if (typeof callback === 'function') {
                    LOAD._loadedJs[url].callbacks.push(callback);
                }

                script.src = url;
                // append to head
                document.getElementsByTagName('head')[0].appendChild(script);
            }
            function loadOneByOne(urls, callback) {
                var url = urls.shift();
                // todo: 假设一个某个资源加载失败，闭包将一直无法释放，可能长期占用内存
                if (url) {
                    loadOne(url, function () {
                        loadOneByOne(urls, callback);
                    });
                } else {
                    if (typeof callback === 'function') {
                        callback();
                    }
                }
            }
            return function loadJs(urls, callback) {
                if (Array.isArray(urls)) {
                    return loadOneByOne(urls, callback);
                }
                return loadOne(urls, callback);
            };
        })()
    };

    /**
     * 依赖检查
     *
     * @param {Function} checker 检查函数 返回值为true时成功
     * @param {Number} maxCount 最大检查次数
     * @returns Promise
     * @example:
     * checkDepend(() => {
     *     return typeof $ === 'function'
     * }).then(() => {
     *     // 依赖满足
     * });
     */
    function checkDepend(checker, maxCount) {
        if (!maxCount) {
            maxCount = 1000;
        }
        return new Promise((resolve, reject) => {
            var timer;
            var i = 0;
            go();

            function go() {
                if (checker()) {
                    clearTimeout(timer);
                    resolve();
                    return;
                }
                if (maxCount && ++i >= maxCount) {
                    reject();
                    return;
                }
                timer = setTimeout(go, 200);
            }
        });
    }
    function initAtWho(uEditorEl) {
        var iframe = $(uEditorEl).find('iframe')[0];
        var doc = iframe.contentDocument || iframe.contentWindow.document;
        var ifrEditor = doc.body;

        var $scrollWrap = $('#main-container').css('position', 'relative');
        setTimeout(function () {
            $('.atwho-container').appendTo($scrollWrap);
        }, 200);

        $(ifrEditor)
            .atwho('destroy')
            .atwho('setIframe', iframe)
            .atwho({
                at: '@',
                data: epoint.decodeJson(usersat),
                displayTpl: '<li data-atwho-id="${id}">${name}</li>',
                insertTpl: '<span class="atwho-aimed" style="color:#3c90ff" data-atwho-id="${id}">${atwho-at}${name}</span>',
                limit: 1000
            });
    }

    var dtd;
    var editorPromise;
    // window.__UEDITOR_PROMISE__ = editorPromise;
    var editorInstance;
    var editorEl;

    // 加载编辑器资源
    if (!window.jQuery) {
        urls.unshift(BASE_URL + 'jquery-1.12.4.min.js');
    }
    LOAD.loadJs(urls);
    // 依赖完成后初始化编辑器
    checkDepend(function () {
        return typeof UE === 'object' && typeof UE.getEditor === 'function';
    })
        .then(function () {
            dtd = $.Deferred();
            editorPromise = dtd.promise();
            window.__UEDITOR_PROMISE__ = editorPromise;
            initEditor();
        })
        .catch(function () {
            console.error('似乎资源加载失败了，编辑器无法正常使用');
        });
    /**
     * 创建新的编辑器
     * @param {HTMLElement} wrapper 容器位置
     * @param {string} pos 插入位置 beforebegin, afterbegin, beforeend, afterend
     */
    function createUEditor(wrapper, pos) {
        var el = document.createElement('div');
        el.style.cssText = 'height:100%;min-height:280px;width:100%;box-shadow:2px 2px 6px rgba(0,0,0,.015)';
        el.id = 'xxx-replace-editor';
        wrapper.insertAdjacentElement(pos, el);
        editorEl = el;
        var opt = {
            UEDITOR_HOME_URL: UEDITOR_HOME_URL,
            initialFrameHeight: 280
        };
        if (location.host !== 'oa.epoint.com.cn') {
            opt.toolbars = simpleToolbars;
        }

        var editor = (editorInstance = UE.getEditor(el.id, opt));
        editor.ready(function () {
            dtd.resolve(editor);
        });
    }
    function createBtns(wrapper, pos) {
        var btnHtml = `<div class="clearfix" style="padding: 4px 0px">
        <button class="mini-button l" style="margin-right:10px" onclick="__REPLACE_EDITOR_HELPER__.pushValue">写回内容</button>
        <button class="mini-button l" style="margin-right:10px" onclick="__REPLACE_EDITOR_HELPER__.fetchValue">读取内容</button>
        <!-- <span class="mini-button" style="margin-right:10px" onclick="__REPLACE_EDITOR_HELPER__.toggle">显示源编辑器</span> -->
        <span class="mini-radiobuttonlist l" style="margin-right:10px" onvaluechanged="__REPLACE_EDITOR_HELPER__.toggle2" data="[
            {id:'1',text:'UEditor'},
            {id:'2',text:'原始编辑器'},
            {id:'3',text:'两者都显示'},
        ]" value="1" "></span>
        </div>`;
        if (!window.mini) {
            btnHtml = btnHtml.replace(/(onclick=".+?)"/g, '$1()"');
            btnHtml = btnHtml.replace(
                /<\/div>$/,
                `
            <button class="mini-button l" style="margin-right:10px" onclick="__REPLACE_EDITOR_HELPER__.toggleTo('1')">UEditor</button>
            <button class="mini-button l" style="margin-right:10px" onclick="__REPLACE_EDITOR_HELPER__.toggleTo('2')">原始编辑器</button>
            <button class="mini-button l" style="margin-right:10px" onclick="__REPLACE_EDITOR_HELPER__.toggleTo('3')">两者都显示</button>
            </div>
            `
            );
        }

        wrapper.insertAdjacentHTML(pos, btnHtml);
        if (window.mini) {
            mini.parse(wrapper);
        } else {
            [].slice.call(document.querySelectorAll('.mini-button')).forEach(function (el) {
                el.classList.add('ivu-btn');
                el.classList.add('ivu-btn-primary');
                el.style.lineHeight = '28px';
                el.style.height = '28px';
            });
        }
    }

    window.__REPLACE_EDITOR_HELPER__ = {
        confirm: function (message, title, callback) {
            if (window.mini) {
                return mini.confirm.apply(mini, arguments);
            }

            var action = window.confirm(message) ? 'ok' : 'cancel';
            if (typeof callback === 'function') {
                callback(action);
            }
        },
        pushValue: function () {
            var html = editorInstance.getContent();
            eWebEditorInstance.setValue(html);
        },
        fetchValue: function (force) {
            if (force === true) {
                __REPLACE_EDITOR_HELPER__._fetchValue();
                return;
            }
            __REPLACE_EDITOR_HELPER__.confirm('读取内容将会覆盖当前编辑器内容，是否继续？', '提示', function (e) {
                if (e == 'ok') {
                    __REPLACE_EDITOR_HELPER__._fetchValue();
                }
            });
        },
        _fetchValue: function () {
            __REPLACE_EDITOR_HELPER__._isUserFetch = true;
            var html = eWebEditorInstance.getValue();
            editorInstance.setContent(html);
            setTimeout(() => {
                __REPLACE_EDITOR_HELPER__._isUserFetch = false;
            }, 500);
        },
        toggle: function (e) {
            var showOriginal = eWebEditorInstance.el.style.display == 'none';
            if (showOriginal) {
                e.sender.setText('显示UEditor编辑器');
                eWebEditorInstance.el.style.display = '';
                eWebEditorInstance.doLayout();
            } else {
                e.sender.setText('显示源编辑器');
                eWebEditorInstance.el.style.display = 'none';
            }
        },
        toggle2: function (e) {
            var v = e.value;
            switch (v) {
                case '1':
                    eWebEditorInstance.el.style.display = 'none';

                    editorEl.style.display = '';
                    break;
                case '2':
                    eWebEditorInstance.el.style.display = '';
                    eWebEditorInstance.doLayout();

                    editorEl.style.display = 'none';
                    break;
                case '3':
                    eWebEditorInstance.el.style.display = '';
                    eWebEditorInstance.doLayout();

                    editorEl.style.display = '';
                    break;
                default:
                    break;
            }
        },
        toggleTo: function (v) {
            __REPLACE_EDITOR_HELPER__.toggle2({ value: v });
        },
        imgUploaderUrl: 'https://oa.epoint.com.cn/OA9/fui/js/lib/ewebeditor/jsp/upload.jsp?style=EpointOA&cusdir=&sparams=&skey=&h=oa.epoint.com.cn&action=save&type=image'
    };

    var eWebEditorInstance;

    var pageAdapter = {
        mailFeed: function () {
            // __REPLACE_EDITOR_HELPER__.imgUploaderUrl = 'https://oa.epoint.com.cn/OA9/fui/js/lib/ewebeditor/jsp/upload.jsp?style=EpointOA&cusdir=&sparams=&skey=&h=oa.epoint.com.cn&action=save&type=image';
            __REPLACE_EDITOR_HELPER__.imgUploaderUrl = `${location.protocol}//${location.host}/OA9/fui/js/lib/ewebeditor/jsp/upload.jsp?style=EpointOA&cusdir=&sparams=&skey=&h=${location.hostname}&action=save&type=image`;
            var $wraperEl = $('#feedback-content').parent();
            eWebEditorInstance = mini.get('feedback-content');
            setTimeout(() => {
                initAtWho(editorEl);
            }, 1000);
            // 反馈后清空编辑器
            $('.btn-feedback').on('click', () => {
                setTimeout(function () {
                    editorInstance.setContent('');
                }, 500);
            });
            return Promise.resolve($wraperEl);
        },
        mailSend: function () {
            __REPLACE_EDITOR_HELPER__.imgUploaderUrl = `${location.protocol}//${location.host}/OA9/fui/js/lib/ewebeditor/jsp/upload.jsp?style=EpointOA&cusdir=&sparams=&skey=&h=${location.hostname}&action=save&type=image`;
            var $wraperEl = $('#mailcontent').parent();
            eWebEditorInstance = mini.get('mailcontent');
            return Promise.resolve($wraperEl);
        },
        knowledgeFeed: function () {
            __REPLACE_EDITOR_HELPER__.imgUploaderUrl = 'https://fdoc.epoint.com.cn/onlinedoc/fui/js/lib/ewebeditor/jsp/upload.jsp?style=coolblue&cusdir=&sparams=&skey=&h=fdoc.epoint.com.cn&action=save&type=image';
            var $wraperEl = $('#txtContent').parent();
            eWebEditorInstance = mini.get('txtContent');
            return Promise.resolve($wraperEl);
        },
 		knowledgePost: function () {
            __REPLACE_EDITOR_HELPER__.imgUploaderUrl = 'https://fdoc.epoint.com.cn/onlinedoc/fui/js/lib/ewebeditor/jsp/upload.jsp?style=coolblue&cusdir=&sparams=&skey=&h=fdoc.epoint.com.cn&action=save&type=image';
            var $wraperEl = $('#Content').parent();
            eWebEditorInstance = mini.get('Content');
            return Promise.resolve($wraperEl);
        },
        // HUHA 增加需求评审设计反馈 2024-03-05
        demandFeedbackAdd: function () {
            __REPLACE_EDITOR_HELPER__.imgUploaderUrl = 'https://fdoc.epoint.com.cn/onlinedoc/fui/js/lib/ewebeditor/jsp/upload.jsp?style=coolblue&cusdir=&sparams=&skey=&h=fdoc.epoint.com.cn&action=save&type=image';
            var $wraperEl = $('#feedbackcontent').parent();

            eWebEditorInstance = mini.get('feedbackcontent');
            return Promise.resolve($wraperEl);
        },
        communityFeed: function () {
            // 论坛使用vue 此时dom和编辑器可能还未就绪
            return checkDepend(() => {
                return typeof EWEBEDITOR == 'object' && $('.commentoperation .wrap').length && Object.keys(EWEBEDITOR.Instances).length;
            }).then(function () {
                __REPLACE_EDITOR_HELPER__.imgUploaderUrl = `${location.protocol}//${location.host}/OA9/fui/js/lib/ewebeditor/jsp/upload.jsp?style=EpointOA&cusdir=&sparams=&skey=&h=${location.hostname}&action=save&type=image`;
                var $wraperEl = $('.commentoperation .wrap');
                // 这里不是 mini 的实例， mock 一个具备相似接口的
                var k = Object.keys(EWEBEDITOR.Instances)[0];
                eWebEditorInstance = {
                    doLayout: function () { },
                    getValue: function () {
                        return EWEBEDITOR.Instances[k].getHTML();
                    },
                    setValue: function (v) {
                        return EWEBEDITOR.Instances[k].setHTML(v);
                    },
                    el: $('#' + k.replace(/^ewebeditor_/, 'component-content_'))[0]
                };
                // 反馈后清空编辑器
                $('.reply-btn.ivu-btn').on('click', () => {
                    setTimeout(function () {
                        editorInstance.setContent('');
                    }, 500);
                });
                return Promise.resolve($wraperEl);
            });
        },
        communitySend: function () {
            return checkDepend(() => {
                return typeof EWEBEDITOR == 'object' && $('.posts-content .wrap').length && Object.keys(EWEBEDITOR.Instances).length;
            }).then(function () {
                __REPLACE_EDITOR_HELPER__.imgUploaderUrl = `${location.protocol}//${location.host}/OA9/fui/js/lib/ewebeditor/jsp/upload.jsp?style=EpointOA&cusdir=&sparams=&skey=&h=${location.hostname}&action=save&type=image`;
                var $wraperEl = $('.posts-content .wrap');
                $wraperEl.css({
                    position: 'relative',
                    'z-index': 1
                });
                // 这里不是 mini 的实例， mock 一个具备相似接口的
                var k = Object.keys(EWEBEDITOR.Instances)[0];
                eWebEditorInstance = {
                    doLayout: function () { },
                    getValue: function () {
                        return EWEBEDITOR.Instances[k].getHTML();
                    },
                    setValue: function (v) {
                        return EWEBEDITOR.Instances[k].setHTML(v);
                    },
                    el: $('#' + k.replace(/^ewebeditor_/, 'component-content_'))[0]
                };
                return Promise.resolve($wraperEl);
            });
        },
        demandAdd: function () {
            __REPLACE_EDITOR_HELPER__.imgUploaderUrl = `${location.protocol}//${location.host}/OA9/fui/js/lib/ewebeditor/jsp/upload.jsp?style=EpointOA&cusdir=&sparams=&skey=&h=${location.hostname}&action=save&type=image`;
            return checkDepend(() => {
                return typeof EWEBEDITOR == 'object' &&  mini.get('demanddesc') && mini.get('demanddesc').isDisplay();
            }).then(function () {
                eWebEditorInstance = mini.get('demanddesc');
                // 此页面没有单独容器，需要创建一个包裹，否则样式会有问题
                var $el = $('#demanddesc');
                var $wraperEl = $('<div/>');

                $el.before($wraperEl);
                $el.appendTo($wraperEl);
                // 页面有设置模板功能， 监听事件做值同步 重写方法实现
                var _setV = eWebEditorInstance.setValue;
                eWebEditorInstance.setValue = function setValue() {
                    _setV.apply(this, arguments);
                    __REPLACE_EDITOR_HELPER__.fetchValue(true);
                };

                return Promise.resolve($wraperEl);
            });
        }
    };

    function initEditor() {
        var promise;
        console.log('path: ' + location.pathname);
        // 邮件反馈页面
        if (/mail\/mailreceivedetail/i.test(location.pathname) || /mail\/mailsenddetail/i.test(location.pathname)) {
            promise = pageAdapter.mailFeed();
        } else if (/mail\/mailsend/i.test(location.pathname)) {
            // 发邮件页面
            promise = pageAdapter.mailSend();
        } else if (/onlinedoc\/kfzknowledge\/customoa\/infofeedback/i.test(location.pathname)) {
            // 知识库反馈页面
            promise = pageAdapter.knowledgeFeed();
            // 做了同步 无需都显示出来
            // setTimeout(() => {
            //     __REPLACE_EDITOR_HELPER__.toggleTo('3');
            // }, 100);
        }else if (/kfzknowledge\/kfzknowledge\/postquestion_workflow/.test(location.pathname)) {
            // 知识库提问页面
            promise = pageAdapter.knowledgePost();
        }
		else if (location.pathname === '/topic/frame/pages/communitynew/index') {
            // 论坛反馈
            if (/^#\/detail/i.test(location.hash)) {
                promise = pageAdapter.communityFeed();
            } else if (/^#\/publish/i.test(location.hash)) {
                // 论坛发帖
                promise = pageAdapter.communitySend();
                // 可能有草稿 需要将草稿内容同步到新编辑器
                if (/articleId=/.test(location.hash)) {
                    // ewebeditor 没有事件获取到内容更新 迟延处理
                    setTimeout(() => {
                        editorPromise.then(function () {
                            __REPLACE_EDITOR_HELPER__.fetchValue(true);
                        });
                    }, 1000);
                }
            }
        }
        else if (/demandbasicinfonew_workflow/.test(location.pathname)) {
            promise = pageAdapter.demandAdd();
        }
        else if ('/productrelease/cpzt/demandmanagejy/demandfeedbackadd' === location.pathname) {
            // HUHA 需求评审设计添加反馈页面
            promise = pageAdapter.demandFeedbackAdd();

            // 页面默认值调整
            mini.get('feedbackcontent').setValue('需求阅读理解、需求沟通评审、需求规划，流程审核及提交。');
            mini.get('associationloghour').setValue('0.1');
            mini.get('iscpzc').set({ "checked": "false" });
            $("#noticeuseruserrow").addClass("hidden");
            var projectguid = $("#projectguid").find("input[type='radio']:last").val();
            mini.get('projectguid').setValue(projectguid);
            $("#projectguid").find("input[type='radio']:last").parent().addClass("mini-radiobuttonlist-item-selected");

            // 将ewebeditor的内容写到editor
            editorPromise.then(function () {
                __REPLACE_EDITOR_HELPER__.fetchValue(true);
            });

        }
        else if('/productrelease/cpzt/demandmanagejy/demandbasicinfonew_detail' === location.pathname ){
            // HUHA 增加需求设计默认值自动赋值
            mini.get('sensitivetypewrite').setValue('');// 敏感类型 默认都不选
            mini.get('isreadwarning').setValue('1');// 是否阅读需求预警提示 默认是
            mini.get('isneedprcon').setValue('0');// 需要UE/UI设计 默认否
            mini.get('isneedprdcon').setValue('0');// 需要PRD文档 默认是
            mini.get('isneeddetailcon').setValue('0');// 需要详细设计 默认是
            mini.get('isneedtest').setValue('1');// 需要测试部测试 默认是

            mini.get('demandqualityscore').setValue('5');
            initFacilityValue(true, 'demandqualityscore','5');
            initFacilityValue(false, 'demandqualityscore' ,'5');

            mini.get('developpriority').setValue('2');
            initFacilityValue(true, 'developpriority' ,'2');
            initFacilityValue(false, 'developpriority' ,'2');

            mini.get('realizedifficulty').setValue('2');
            initFacilityValue(true, 'realizedifficulty' ,'2');
            initFacilityValue(false, 'realizedifficulty' ,'2');

            mini.get('productvalue').setValue('2');
            initFacilityValue(true, 'productvalue' ,'2');
            initFacilityValue(false, 'productvalue' ,'2');

        }
         else if('/productrelease/cpzt/demandmanagejy/demandbasicinfonew_splitdetail' === location.pathname){
            // HUHA 增加需求设计默认值自动赋值
            mini.get('sensitivetypewrite').setValue('');// 敏感类型 默认都不选
            mini.get('isreadwarning').setValue('1');// 是否阅读需求预警提示 默认是
            mini.get('isneedprcon').setValue('0');// 需要UE/UI设计 默认否
            mini.get('isneedprdcon').setValue('0');// 需要PRD文档 默认是
            mini.get('isneeddetailcon').setValue('1');// 需要详细设计 默认是
            mini.get('isneedtest').setValue('1');// 需要测试部测试 默认是

            mini.get('demandqualityscore').setValue('4');
            initFacilityValue(true, 'demandqualityscore','4');
            initFacilityValue(false, 'demandqualityscore' ,'4');

            mini.get('developpriority').setValue('2');
            initFacilityValue(true, 'developpriority' ,'2');
            initFacilityValue(false, 'developpriority' ,'2');

            mini.get('realizedifficulty').setValue('2');
            initFacilityValue(true, 'realizedifficulty' ,'2');
            initFacilityValue(false, 'realizedifficulty' ,'2');

            mini.get('productvalue').setValue('2');
            initFacilityValue(true, 'productvalue' ,'2');
            initFacilityValue(false, 'productvalue' ,'2');

        }

        if (!promise) {
            return;
        }

        // 等待就绪后创建编辑器 执行替换
        promise.then(function ($wraperEl) {
            if ($wraperEl) {
                createUEditor($wraperEl[0], 'beforeend');
                createBtns($wraperEl[0], 'afterbegin');
                eWebEditorInstance.el.style.display = 'none';
            }
        });

        // 正常情况下 始终从UEditor 同步到 原始编辑器，免得需要手动点
        editorPromise.then((editor) => {
            editor.addListener('contentchange', function () {
                if (!__REPLACE_EDITOR_HELPER__._isUserFetch) {
                    __REPLACE_EDITOR_HELPER__.pushValue();
                }
            });
        });
    }

    function initFacilityValue(canEdit, starclass ,value) {
        var $starControl = $('.'+starclass+'');
        if ($starControl.attr("inited") == '1') {
            return;
        }

        var oneBrightUrl = Util.getRootPath() + "cpzt/demandmanage/image/star/one_star_bright.png";// 1亮
        var oneGrayUrl = Util.getRootPath() + "cpzt/demandmanage/image/star/one_star_gray.png";// 1灰

        var starData = {
            "1" : "",
            "2" : "",
            "3" : "",
            "4" : "",
            "5" : ""
        };

        if (canEdit) {
            // 初始化html
            var html = '';
            for ( var key in starData) {
                html += '<a href="javascript:void(0);" style="width:12px" key="' + key + '"><img src="' + oneGrayUrl + '"/></a>';
            }
            html += '<span class="message" style="width:40px;margin-left:10px;color:red"></span>';
            $starControl.append(html);
            // 点击亮星与设值
            $('.'+starclass+'').on("click", "a", function() {
                var $this = $(this);
                // 亮灯
                $this.find("img").attr("src", oneBrightUrl);
                $this.nextAll().find("img").attr("src", oneGrayUrl);
                $this.prevAll().find("img").attr("src", oneBrightUrl);
                // 说明文字
                var key = $this.attr("key");
                $this.parent().find(".message").html(starData[key]);// 设置提示语，下面以此类推
                // 表单放值
                mini.get($this.parent().attr("star")).setValue(key);
            });
            // 鼠标移入移出效果
            $('.'+starclass+'').on("mouseover", "a", function() {
                var $this = $(this);
                $this.find("img").attr("src", oneBrightUrl);
                $this.nextAll().find("img").attr("src", oneGrayUrl);
                $this.prevAll().find("img").attr("src", oneBrightUrl);
                // 说明文字
                var key = $this.attr("key");
                $starControl.find(".message").html(starData[key]);
            });
            $('.'+starclass+'').on("mouseout", "a", function() {
                var $this = $(this);
                var key = $this.parent().find("input").val();
                if (key) {
                    var $target = $this.parent().find("a[key='" + key + "']");
                    $target.click();
                } else {
                    $this.parent().find("img").attr("src", oneGrayUrl);
                    $starControl.find(".message").html("");
                }
            });
            $('.'+starclass+' a').trigger("mouseout");
            $starControl.attr("inited", "1");
        }
        else {
            // 初始化html
            var html1 = '';
            for ( var key1 in starData) {
                if (key <= value) {
                    html1 += '<a href="javascript:void(0);" style="width:12px" key="' + key1 + '"><img src="' + oneBrightUrl + '"/></a>';
                }
                else {
                    html1 += '<a href="javascript:void(0);" style="width:12px" key="' + key1 + '"><img src="' + oneGrayUrl + '"/></a>';
                }
            }
            html1 += '<span class="message" style="width:40px;margin-left:10px;color:red"></span>';
            $starControl.append(html1);
            $starControl.attr("inited", "1");
        }
    }

    // __UEDITOR_PROMISE__.then(function () {
    //     //
    // });
    var s = document.createElement('script');
    s.async = true;
    s.defer = true;
    s.src = 'https://fe.epoint.com.cn/umami/script.js';
    s.setAttribute('data-website-id', 'a9992191-a4ac-4234-81dd-ddcf2cff3443');
    document.body.appendChild(s);

    checkDepend(() => !!window.umami).then(() => {
        umami.track();
        umami.track('version', { value: version });
    });
})();